package com.fitso.wicket.page;

import java.io.Serializable;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.protocol.http.WebResponse;

/**
 * No cache implementation of {@link WebPage} that prevents pages from being
 * cached by the web server.
 * 
 * @author timothystorm
 */
public class NoCacheWebPage extends WebPage implements Serializable {
	// Only change on breaking changes, i.e., removing fields
	private static final long serialVersionUID = 1L;

	private static final String PRAGMA = "Pragma";
	private static final String NO_CACHE = "no-cache";
	private static final String CACHE_CONTROL = "Cache-Control";
	private static final String CACHE_ARGS = "no-cache, max-age=0, must-revalidate, no-store";
	private static final String EXPIRES = "Expires";
	private static final String ZERO = "0";

	@Override
	protected void setHeaders(WebResponse response) {
		super.setHeaders(response);

		response.setHeader(PRAGMA, NO_CACHE);
		response.setHeader(CACHE_CONTROL, CACHE_ARGS);
		response.setHeader(EXPIRES, ZERO);
	}
}
